﻿<!--
 Peter
 Created by: Peter Development Team
    http://peter.codeplex.com/
 
 GNU General Public License version 2 (GPLv2)
    http://peter.codeplex.com/license
 
  This code is provided on an AS IS basis, with no WARRANTIES,
  CONDITIONS or GUARANTEES of any kind.
-->
<Window x:Class="Peter.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:logic="clr-namespace:Peter.Logic"
        xmlns:view="clr-namespace:Peter.View"
        xmlns:xcad="http://schemas.xceed.com/wpf/xaml/avalondock"
        xmlns:properties="clr-namespace:Peter.Properties"
        xmlns:mainMenu="clr-namespace:Peter.Common.MainMenu;assembly=Peter.Common"
        xmlns:common="clr-namespace:Peter.Common;assembly=Peter.Common"
        xmlns:icons="clr-namespace:Peter.Common.Icons;assembly=Peter.Common"
        xmlns:bc="clr-namespace:Peter.Common.BindingConverters;assembly=Peter.Common"
        xmlns:dialog="clr-namespace:Peter.Common.Dialog;assembly=Peter.Common"
        xmlns:notificationBar="clr-namespace:Peter.Common.NotificationBar;assembly=Peter.Common"
        Height="{Binding Source={x:Static properties:Settings.Default}, Path=Height, Mode=TwoWay}"
        Width="{Binding Source={x:Static properties:Settings.Default}, Path=Width, Mode=TwoWay}"
        Top="{Binding Source={x:Static properties:Settings.Default}, Path=Top, Mode=TwoWay}"
        Left="{Binding Source={x:Static properties:Settings.Default}, Path=Left, Mode=TwoWay}"
        Background="{StaticResource BaseBackground}"
        MinWidth="500"
        MinHeight="300"
        Icon="/Peter;component/Editor.ico"
        Title="{Binding Path=Title}"
        AllowDrop="True"
        Drop="OnDropEvent">
   <Window.DataContext>
      <logic:ModelPeterMain />
   </Window.DataContext>

   <Window.Resources>
      <CollectionViewSource x:Key="_QuickOpenItems"
                               Source="{Binding Path=QuickOpen.QuickOpenItems}">
         <CollectionViewSource.GroupDescriptions>
            <PropertyGroupDescription PropertyName="Header" />
         </CollectionViewSource.GroupDescriptions>
      </CollectionViewSource>
      <bc:NullNotVisibleConverter x:Key="_NullNotVisi" />
   </Window.Resources>

   <Grid>
      <Grid.RowDefinitions>
         <RowDefinition Height="Auto" />
         <RowDefinition Height="Auto" />
         <RowDefinition Height="*" />
         <RowDefinition Height="Auto" />
      </Grid.RowDefinitions>

      <!-- MAIN MENU -->
      <mainMenu:MainMenu Grid.Row="0"
                     IconSize="Large"
                     QuickAccessMenuItems="{Binding Path=MenuModel.QuickAccessItems}"
                     ItemsSource="{Binding Path=MenuModel.Items}" />

      <!-- NOTIFICATION BAR -->
      <notificationBar:MainWindowNotificationBar Grid.Row="1" />

      <!-- DOCKING MANAGER -->
      <xcad:DockingManager Grid.Row="2"
                           x:Name="_DockMan"
                           DocumentsSource="{Binding Path=Documents}"
                           AnchorablesSource="{Binding Path=ToolWindows}"
                           ActiveContent="{Binding Path=ActiveContent, Mode=TwoWay}"
                           DocumentContextMenu="{Binding Path=ContextMenuModel.DocumentContextMenu, Mode=TwoWay}">

         <xcad:DockingManager.LayoutItemTemplateSelector>
            <common:DockTemplateSelector>
               <common:DockTemplateSelector.DataTemplates>
                  <DataTemplate DataType="{x:Type logic:ModelEditor}">
                     <view:ViewEditor />
                  </DataTemplate>
                  <DataTemplate DataType="{x:Type logic:ModelOptions}">
                     <view:ViewOptions />
                  </DataTemplate>
                  <DataTemplate DataType="{x:Type logic:ModelFileExplorer}">
                     <view:ViewFileExplorer />
                  </DataTemplate>
                  <DataTemplate DataType="{x:Type logic:ModelImageViewer}">
                     <view:ViewImageViewer />
                  </DataTemplate>
                  <DataTemplate DataType="{x:Type logic:ModelZipExplorer}">
                     <view:ViewZipExplorer />
                  </DataTemplate>
                  <DataTemplate DataType="{x:Type logic:ModelCodeExplorer}">
                     <view:ViewCodeExplorer />
                  </DataTemplate>
                  <DataTemplate DataType="{x:Type logic:ModelApplicationOutput}">
                     <view:ViewConsoleOutput />
                  </DataTemplate>
                  <DataTemplate DataType="{x:Type logic:ModelTerminal}">
                     <view:ViewTerminal />
                  </DataTemplate>
                  <DataTemplate DataType="{x:Type logic:ModelWorkspace}">
                     <view:ViewWorkspace />
                  </DataTemplate>
               </common:DockTemplateSelector.DataTemplates>
            </common:DockTemplateSelector>
         </xcad:DockingManager.LayoutItemTemplateSelector>

         <xcad:DockingManager.LayoutItemContainerStyleSelector>
            <common:DockStyleSelector>
               <common:DockStyleSelector.DefaultStyle>
                  <Style TargetType="{x:Type xcad:LayoutItem}">
                     <Setter Property="Title"
                             Value="{Binding Path=Model.Title}" />
                     <Setter Property="ToolTip"
                             Value="{Binding Path=Model.ToolTip}" />
                     <Setter Property="IsSelected"
                             Value="{Binding Path=Model.IsSelected}" />
                     <Setter Property="IsEnabled"
                             Value="{Binding Path=Model.IsEnabled}" />
                     <Setter Property="CanClose"
                             Value="{Binding Path=Model.AllowClose}" />
                     <Setter Property="CanFloat"
                             Value="{Binding Path=Model.CanFloat}" />
                     <Setter Property="ContentId"
                             Value="{Binding Path=Model.ContentId}" />
                  </Style>
               </common:DockStyleSelector.DefaultStyle>
               <common:DockStyleSelector.DocumentStyle>
                  <Style TargetType="{x:Type xcad:LayoutDocumentItem}">
                     <Setter Property="Title"
                             Value="{Binding Path=Model.Title}" />
                     <Setter Property="ToolTip"
                             Value="{Binding Path=Model.ToolTip}" />
                     <Setter Property="IsSelected"
                             Value="{Binding Path=Model.IsSelected}" />
                     <Setter Property="IsEnabled"
                             Value="{Binding Path=Model.IsEnabled}" />
                     <Setter Property="CanClose"
                             Value="{Binding Path=Model.AllowClose}" />
                     <Setter Property="CloseCommand"
                             Value="{Binding Path=Model.CloseCommand}" />
                     <Setter Property="CanFloat"
                             Value="{Binding Path=Model.CanFloat}" />
                     <Setter Property="ContentId"
                             Value="{Binding Path=Model.ContentId}" />
                  </Style>
               </common:DockStyleSelector.DocumentStyle>
               <common:DockStyleSelector.ToolWindowStyle>
                  <Style TargetType="{x:Type xcad:LayoutAnchorableItem}">
                     <Setter Property="Title"
                             Value="{Binding Path=Model.Title}" />
                     <Setter Property="ToolTip"
                             Value="{Binding Path=Model.ToolTip}" />
                     <Setter Property="IsSelected"
                             Value="{Binding Path=Model.IsSelected}" />
                     <Setter Property="IsEnabled"
                             Value="{Binding Path=Model.IsEnabled}" />
                     <Setter Property="Visibility"
                             Value="{Binding Path=Model.IsVisible}" />
                     <Setter Property="ContentId"
                             Value="{Binding Path=Model.ContentId}" />
                     <Setter Property="CloseCommand"
                             Value="{Binding Path=Model.CloseCommand}" />
                     <Setter Property="HideCommand"
                             Value="{Binding Path=Model.HideCommand}" />
                  </Style>
               </common:DockStyleSelector.ToolWindowStyle>
            </common:DockStyleSelector>
         </xcad:DockingManager.LayoutItemContainerStyleSelector>

         <xcad:DockingManager.DocumentHeaderTemplate>
            <DataTemplate>
               <StackPanel Orientation="Horizontal">
                  <icons:IconDisplay Icon="{Binding Path=Content.Icon}"
                                           IconSize="Medium" />
                  <TextBlock Text="{Binding Path=Title}"
                             Margin="3,0,0,0"
                             TextTrimming="CharacterEllipsis"
                             VerticalAlignment="Center" />
                  <icons:IconDisplay Icon="Lock"
                                           Margin="5,0,0,0"
                                           IconSize="Smallest">
                     <icons:IconDisplay.Visibility>
                        <PriorityBinding FallbackValue="Collapsed">
                           <Binding Path="Content.IsReadOnly"
                                             Mode="OneWay"
                                             Converter="{StaticResource _BoolToVisi}" />
                        </PriorityBinding>
                     </icons:IconDisplay.Visibility>
                  </icons:IconDisplay>
                  <icons:IconDisplay Icon="Asterisk"
                                           Margin="3,0,0,0"
                                           IconSize="Smaller">
                     <icons:IconDisplay.Visibility>
                        <PriorityBinding FallbackValue="Collapsed">
                           <Binding Path="Content.NeedsSaving"
                                             Mode="OneWay"
                                             Converter="{StaticResource _BoolToVisi}" />
                        </PriorityBinding>
                     </icons:IconDisplay.Visibility>
                  </icons:IconDisplay>
               </StackPanel>
            </DataTemplate>
         </xcad:DockingManager.DocumentHeaderTemplate>

         <xcad:DockingManager.DocumentPaneMenuItemHeaderTemplate>
            <DataTemplate>
               <StackPanel Orientation="Horizontal"
                           Margin="0,3">
                  <icons:IconDisplay Icon="{Binding Path=Content.Icon}"
                                     IconSize="Medium" />
                  <TextBlock Text="{Binding Path=Title}"
                             Margin="5,0,0,0"
                             TextTrimming="CharacterEllipsis"
                             VerticalAlignment="Center" />
                  <icons:IconDisplay Icon="Lock"
                                           Margin="5,0,0,0"
                                           IconSize="Smallest">
                     <icons:IconDisplay.Visibility>
                        <PriorityBinding FallbackValue="Collapsed">
                           <Binding Path="Content.IsReadOnly"
                                    Mode="OneWay"
                                    Converter="{StaticResource _BoolToVisi}" />
                        </PriorityBinding>
                     </icons:IconDisplay.Visibility>
                  </icons:IconDisplay>
               </StackPanel>
            </DataTemplate>
         </xcad:DockingManager.DocumentPaneMenuItemHeaderTemplate>

         <xcad:DockingManager.AnchorableHeaderTemplate>
            <DataTemplate>
               <StackPanel Orientation="Horizontal">
                  <icons:IconDisplay Icon="{Binding Path=Content.Icon}"
                                     IconSize="Medium" />
                  <TextBlock Text="{Binding Path=Title}"
                             Margin="3,0,0,0"
                             TextTrimming="CharacterEllipsis"
                             VerticalAlignment="Center" />
               </StackPanel>
            </DataTemplate>
         </xcad:DockingManager.AnchorableHeaderTemplate>

      </xcad:DockingManager>

      <!-- QUICK OPEN LIST -->
      <Grid Grid.Row="0"
              Grid.RowSpan="3"
              Margin="0,25,0,0"
              Visibility="{Binding Path=QuickOpen.IsQuickOpenOpen, Converter={StaticResource _BoolToVisi}}">
         <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto" />
         </Grid.ColumnDefinitions>

         <ListBox Grid.Column="1"
                     MinWidth="200"
                     SelectedIndex="{Binding Path=QuickOpen.SelectedIndex}"
                     ItemsSource="{Binding Source={StaticResource _QuickOpenItems}}">
            <ListBox.GroupStyle>
               <GroupStyle>
                  <GroupStyle.ContainerStyle>
                     <Style TargetType="{x:Type GroupItem}">
                        <Setter Property="Template">
                           <Setter.Value>
                              <ControlTemplate>
                                 <GroupBox Header="{Binding Name}">
                                    <ItemsPresenter Margin="10,0,0,0" />
                                 </GroupBox>
                              </ControlTemplate>
                           </Setter.Value>
                        </Setter>
                     </Style>
                  </GroupStyle.ContainerStyle>
               </GroupStyle>
            </ListBox.GroupStyle>

            <ListBox.ItemContainerStyle>
               <Style TargetType="ListBoxItem">
                  <Setter Property="ToolTip"
                                Value="{Binding Path=ToolTip}" />
               </Style>
            </ListBox.ItemContainerStyle>

            <ListBox.ItemTemplate>
               <DataTemplate>
                  <StackPanel Orientation="Horizontal">
                     <icons:IconDisplay Icon="{Binding Path=Icon}" />
                     <TextBlock Text="{Binding Path=Text}"
                                       Margin="4,0,0,0" />
                  </StackPanel>
               </DataTemplate>
            </ListBox.ItemTemplate>
         </ListBox>
      </Grid>

      <!-- STATUS BAR -->
      <StatusBar Grid.Row="3"
                 AllowDrop="True"
                 Drop="OnDropEvent">
         <StatusBar.ItemsPanel>
            <ItemsPanelTemplate>
               <Grid>
                  <Grid.RowDefinitions>
                     <RowDefinition Height="*" />
                  </Grid.RowDefinitions>
                  <Grid.ColumnDefinitions>
                     <ColumnDefinition Width="*" />
                     <ColumnDefinition Width="Auto" />
                     <ColumnDefinition Width="Auto" />
                     <ColumnDefinition Width="Auto" />
                     <ColumnDefinition Width="Auto" />
                     <ColumnDefinition Width="Auto" />
                     <ColumnDefinition Width="Auto" />
                     <ColumnDefinition Width="Auto" />
                  </Grid.ColumnDefinitions>
               </Grid>
            </ItemsPanelTemplate>
         </StatusBar.ItemsPanel>

         <StatusBarItem Grid.Column="0"
                        Foreground="{Binding Path=StatusModel.Foreground}"
                        Background="{Binding Path=StatusModel.Background}">
            <TextBlock Text="{Binding Path=StatusModel.Status}" />
         </StatusBarItem>

         <StatusBarItem Grid.Column="1"
                        Margin="0,0,1,0"
                        Visibility="{Binding Path=Caret, Converter={StaticResource _NullNotVisi}}">
            <TextBlock Text="Line:" />
         </StatusBarItem>
         <StatusBarItem Grid.Column="2"
                        Visibility="{Binding Path=Caret, Converter={StaticResource _NullNotVisi}}">
            <TextBlock Text="{Binding Path=Caret.Line}" />
         </StatusBarItem>

         <StatusBarItem Grid.Column="3"
                        Margin="0,0,1,0"
                        Visibility="{Binding Path=Caret, Converter={StaticResource _NullNotVisi}}">
            <TextBlock Text="Column:" />
         </StatusBarItem>
         <StatusBarItem Grid.Column="4"
                        Visibility="{Binding Path=Caret, Converter={StaticResource _NullNotVisi}}">
            <TextBlock Text="{Binding Path=Caret.Column}" />
         </StatusBarItem>

         <StatusBarItem Grid.Column="5"
                        Margin="0,0,1,0"
                        Visibility="{Binding Path=Caret, Converter={StaticResource _NullNotVisi}}">
            <TextBlock Text="Offset:" />
         </StatusBarItem>
         <StatusBarItem Grid.Column="6"
                        Visibility="{Binding Path=Caret, Converter={StaticResource _NullNotVisi}}">
            <TextBlock Text="{Binding Path=Caret.Offset}" />
         </StatusBarItem>
         <StatusBarItem Grid.Column="7">
            <TextBlock Text="{Binding Path=CurrentMemory}" />
         </StatusBarItem>
      </StatusBar>

      <!-- DIALOG CONTAINER -->
      <dialog:MainWindowDialog Grid.Row="0"
                                 Grid.RowSpan="4" />

   </Grid>
</Window>
